<%@page import="com.jxtti.service.AdminUserRoleService"%>
<%@page import="com.jxtti.entity.Admin_RoleType"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
com.jxtti.model.User userInfo = com.jxtti.utils.AuthUtil.getUserInfo(request);
String orgId=null;
//if(userInfo.getDistrictId()==null || userInfo.getDistrictId().equals("0")){ //非超管
if(userInfo.getRoleId()!=com.jxtti.utils.Constants.AdminRole){ //非超管
	orgId=userInfo.getOrgId().toString();
}

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=9" />
		<meta http-equiv="pragma" content="no-cache" />
		<title>文章列表</title>
		<%@ include file="../../../common/Admin-list.jsp"%>
		<script type="text/javascript" src="<%=bpath %>Scripts/common/common.js"></script> 
 		<link rel="stylesheet" type="text/css" href="<%=basePath %>Themes/default/css/jquery.datetimepicker.css"/>    
		<script type="text/javascript" src="<%=basePath %>Scripts/jquery/jquery.datetimepicker.js"></script>
	
		<script type="text/javascript">
		$(function(){	
			if(<%=orgId %>!=null){ //是否管理员
				$("#orgId").combotree("setValue",<%=orgId %>);	
				$("#orgId").combotree('disable');
			}
			//加载人员
			$('#dataGridArticleList').datagrid({
				height:'495',
				rownumbers:true,//设置为true将显示行数					
				striped:true, //设置为true将交替显示行背景
				fitColumns:true,//设置为true将自动使列适应表格宽度以防止出现水平滚动
				animate:true,											
				idField:'id',//id字段	
				pagination : true,//分页控件
				pageSize : 10,
			    pageList : [10, 20, 30],
			    url : '../ArticleList/list.json?noAdmin=yes',
				loadMsg : '数据装载中......',								
				columns:[[					          	
							{ field:'ck',checkbox:true },
							{field:'id',hidden:true,editor:{type:'text'}},
							{field:'categoryID',title:'所属栏目',hidden:true,width:120,align:'center',editor:{type:'text'}},
							{field:'categoryName',title:'所属栏目',width:100,align:'left',editor:{type:'text'}},
							{field:'title',title:'文章标题',width:250,align:'left',editor:{type:'text'},								
								//预览
								formatter:function(value,row,index){
									var html="";
									var url="/SiteIndex/article.htm?id="+encode64((row.id).toString())+'&preview=yes';
									
									if($.trim(row.titleColor)!=""){
										html='<a href="<%=basePath %>'+url+'" target="_blank" ><img src="<%=basePath %>pages/Admin/Images/search.gif" title="点击预览" style="margin-bottom:-3px"> &nbsp;</a><font style="color:'+row.titleColor+';">'+value+'</font>';						   
									}else{
										html='<a href="<%=basePath %>'+url+'" target="_blank" ><img src="<%=basePath %>pages/Admin/Images/search.gif" title="点击预览" style="margin-bottom:-3px"> &nbsp;</a>'+value;						   
									}
						    		return html;						    	
						    	}
							},
							{field:'titleColor',title:'标题颜色',hidden:true,width:100,align:'center',editor:{type:'text'}},							
							{field:'status',title:'文章状态',hidden:true,width:100,align:'center',editor:{type:'text'}},								
							{field:'issue',title:'显示',width:40,align:'center',editor:{type:'text'},
							    formatter:function(value){ 
						    		if(value=="1"){
						    			ss='<span disabled="disabled"><input type="checkbox" checked="checked" disabled="disabled"></span> ';
						    		}else{
						    			ss='<span disabled="disabled"><input type="checkbox" disabled="disabled"></span> ';
						    		}
						    		return ss;
						    	 }
							},	
							{field:'isHomePic',title:'图片推广',width:50,align:'center',editor:{type:'text'},
								formatter:function(value){ 
						    		if(value=="1"){
						    			return '√';
						    		}else{
						    			return '';
						    		}
						    	 }	
							},	
							{field:'is_contribute',title:'县级投稿',width:50,align:'center',editor:{type:'text'},
								formatter:function(value){ 
						    		if(value=="1"){
						    			return '<span disabled="disabled">√</span> ';
						    		}else{
						    			return '';
						    		}
						    	 }
							},	
							{field:'sortID',title:'排序',hidden:true,width:40,align:'center',editor:{type:'text'}},	
							{field:'clicks',title:'点击数',width:40,align:'center',editor:{type:'text'}},	
							{field:'articleSite',title:'所属站点',width:50,align:'left',editor:{type:'text'},
								formatter:function(value){ 
						    		if(value=="0"){ // 0 外网,1内网，2内外网
						    			return '外网';
						    		}else if(value=="1"){
						    			return '内网';
						    		}else{
						    			return '外网&内网';
						    		}						    		
						    	 }
							},	
							{field:'isRecommend',title:'置顶',width:50,align:'center',editor:{type:'text'},
								formatter:function(value){ 
						    		if(value=="1"){
						    			return '√';
						    		}else{
						    			return '';
						    		}						    		
						    	 }
							},
							{field:'modifyDate',title:'编辑时间',width:90,align:'center',editor:{type:'text'},sortable:'true',
								formatter:function(value,row,index){  
	                        		var unixTimestamp = new Date(value);  
	                        		return unixTimestamp.format("yyyy-MM-dd hh:mm"); 
	                        	}
							},								
							{field:'fk_orgId',title:'组织机构id',hidden:true,width:100,align:'center',editor:{type:'text'}},	
							{field:'orgIdName',title:'组织机构',width:100,align:'left',editor:{type:'text'}}
						]]    
	          
			});					
			
		});
		
		function addArticle(){ //新增文章  
			art.dialog.open('../ArticleList/addInterface.htm?type=add',{
				title: '',
				id:'editDialog',
				lock:true,
			  	width: '100%',
			    height: '100%',
		    	close : function () {
		    		$('#dataGridArticleList').datagrid('reload');
		    	}																   												   
			});
      	}
		
		function leftAddArticle(nodesId,nodeName) {	       
        	art.dialog.open('../ArticleList/addInterface.htm?type=leftAdd&categoryID='+nodesId+'&categoryName='+nodeName,{
				title: '',
				id:'editDialog',
				lock:true,
		  		width: '100%',
		    	height: '100%',
		    	close : function () {
		    		$('#dataGridArticleList').datagrid('reload');
		    	}												   												   
	   		});
	    }
		 
		function editArticle(){ //修改文章  getSelected  
			var row = $('#dataGridArticleList').datagrid('getSelected');
			if (row) {								
				art.dialog.open('../ArticleList/updateInterface.htm?type=edit&id='+row.id,{
					title: '',
					id:'editDialog',
					lock:true,
				  	width: '100%',
				    height: '100%',
			    	close : function () {
			    		$('#dataGridArticleList').datagrid('reload');
			    	}
			            
				});
			}else{				
				$.messager.alert('系统提示', '请选择一行!', 'warning');
			}			
      	}
		
		function delArticle(){  //删除操作
			var selRow = $('#dataGridArticleList').datagrid('getSelections');
			if (selRow.length>0) {			
				var ids=[];  
				for (var i = 0; i < selRow.length; i++) {  
				    var id=selRow[i].id;     
				    ids.push(id); //然后把单个id循环放到ids的数组中  
				} 				
				
				art.dialog({
					icon: 'question',	
					width:250,
				    content: '你确定删除该数据？',
				    ok: function () {
			    		$.ajax({
							type:'POST',
							dataType:'json',
							async:false,
							url:'../ArticleList/delete.json',
							data:{ids:ids.toString(),delSub:true},
							success:function(data){
								if(data.success=true){									
									art.dialog.alert('删除成功！');
									//window.location.reload();  
									refresh();
								}else{
									art.dialog.alert('删除失败，请联系管理员！');
								}
							}
						});				    			
				    },
				    cancelVal: '取消',
				    cancel: true 
				});
			}else{				
				$.messager.alert('系统提示', '请选择一行!', 'warning');
			}
      	} 
		
		function refresh(){
			$('#dataGridArticleList').datagrid('reload');
		}
			
		</script>
		
	</head>
<body>		
		<div class="easyui-panel" fit="true" type="panel" border="false">			
		<table id="dataGridArticleList" type="dataGrid"	data-options="toolbar:'#toolBar'">
		</table>		
		<div id="toolBar" style="height: auto;padding:0px;">
			<!--表单  搜索栏-->
			<div id="filter" class="module">					
				<ul>				 
					<li>
						<input type="hidden" id="categoryIds" value="" />		
					</li>	
					<li>
						<label>发表时间：</label>
						<input type="text" value="" id="timestart" class="inputdate" />						
					</li>
					<li>
						<label>-&nbsp;</label>
						<input type="text" value="" id="timeend" class="inputdate" />						
					</li>
					<li>
						<label>发表组织：</label>
						<select id="orgId" name="orgId" class="easyui-combotree" multiple style="width:250px;"   
        			data-options="url:'../district/findByPidAll.json',panelHeight:245"></select>						
					</li>
					
				
					<li>
						<label>文章标题：</label>
						<input type="text" value="" id="title" style="width:200px;"/>						
					</li>
					
					<li>
						<input type="button" class="btn btn-blue-h20-w2" value="查询" onclick="searchList()" />
					</li>
					
					<li>
						<label>&nbsp;&nbsp;&nbsp;&nbsp;所属站点：</label>						
						<select id="articleSite" class="datatype"  name="articleSite">
							<option value="-1" selected="selected">所有文章</option>
							<option value="0">&nbsp;&nbsp;外网</option>							
							<option  value="1">&nbsp;&nbsp;内网</option>	
							<option  value="2">&nbsp;&nbsp;内网&外网&nbsp;&nbsp;&nbsp;&nbsp;</option>	
						</select>		
					</li>									
					<li>
						&nbsp;&nbsp;&nbsp;&nbsp;
						 <input id="issue" type="checkbox" name="issue" checked="checked" value="1"  style="width:10px;vertical-align:middle;" />
                	 	 <label for="issue" style="margin-right:8px;">网站显示</label>
	                	  
	                	 <input id="isHomePic" type="checkbox" name="isHomePic"  value="1" style="width:10px;vertical-align:middle;" />
	                	 <label for="isHomePic" style="margin-right:8px;">图片推广</label>
	                	  
	                	 <input id="is_contribute" type="checkbox" name="is_contribute" value="1" style="width:10px;vertical-align:middle;" />
	                	 <label for="is_contribute" style="margin-right:8px;">县级投稿</label>	
	                	 			
					</li>
					
				</ul>
				<div class="clear"></div>
			</div>
			<!--表单  列表栏-->
			<div class="list module">
				<div class="hd">
					<h2 class="t">数据列表</h2>
					<span class="handle4filter" title="显示/隐藏查询条件"></span>
				</div>
				<div class="bd">
					<div id="toolbar">
						<ul id="buttonPlace">																
							<li>
								<a  href="javascript:addArticle()" class="icon add" hideFocus="false"><span class = "glyphicon glyphicon-plus" style="display:in-line"></span>增加</a>
							</li>
							<li>
								<a href="javascript:editArticle()" class="icon edit"  hideFocus="false"><span class = "glyphicon glyphicon-edit" style="display:in-line"></span>修改</a>
							</li> 				
							<li>
								<a href="javascript:delArticle()"  class="icon dele"  hideFocus="false"><span class = "glyphicon glyphicon-trash" style="display:in-line"></span>删除</a>
							</li>				
						</ul>
					</div>
				</div>
			</div>
		</div>		
		<div id="win"></div>
	</div>
	<script type="text/javascript">	
	$('#timestart').datetimepicker({		
		maxDate : 0 ,  //'new Date()'
		format:'Y-m-d',
		lang:'ch',
		timepicker:false
	});	
	
	$('#timeend').datetimepicker({		
		maxDate : 0 ,  //'new Date()'
		format:'Y-m-d',
		lang:'ch',
		timepicker:false,
		onShow:function( ct ){				
				this.setOptions({		
					minDate:$('#timestart').val()?$('#timestart').val():false,formatDate:'Y-m-d'
			    })			  
		}		
	});
		
	
	function searchList() {
		var queryParams = $('#dataGridArticleList').datagrid('options').queryParams;			
		queryParams.categoryID =$('#categoryIds').val();//文章类目	
		queryParams.title = $('#title').val();
		queryParams.startTime = $('#timestart').val();
		queryParams.endTime = $('#timeend').val();
		queryParams.fk_orgId=$("#orgId").combotree("getValues").join(',');	
		
		if($('#articleSite').val()=="-1"){
			delete queryParams.articleSite;
		}else{
			queryParams.articleSite =$('#articleSite').val();
		}
				
		if($('#issue').is(':checked')) {
			queryParams.issue =$('#issue').val();//是否显示
		}else{
			delete queryParams.issue;
		}
		if($('#isHomePic').is(':checked')) {			
			queryParams.isHomePic=$('#isHomePic').val();//图片推广
		}else{
			delete queryParams.isHomePic; //从json中删除这一项			
		}		
		if($('#is_contribute').is(':checked')) {
			queryParams.is_contribute =$('#is_contribute').val();//县级投稿
		}else{			
			delete queryParams.is_contribute;
		}
		$('#dataGridArticleList').datagrid('load');
		$('#dataGridArticleList').datagrid('clearSelections');
	}
	
	$(function() {
		if($('#timestart').val()==""){					
			var d = new Date(); //获取今天日期
			d.setDate(d.getDate() - 7);				
			var mon=d.getMonth()+1;
			var day=d.getDate();			
			var str = d.getFullYear()+"-"+(mon<10 ? "0"+ mon : mon)+"-"+(day<10?"0"+day:day);				
			$('#timestart').val(str);	
		}
		
		if($('#timeend').val()==""){
			var d = new Date();
			var mon=d.getMonth()+1;
			var day=d.getDate();			
			var str = d.getFullYear()+"-"+(mon<10 ? "0"+ mon : mon)+"-"+(day<10?"0"+day:day);			
			$('#timeend').val(str);			
		}
	});
	
	</script>
</body>
</html>